/**
 * 
 */
app.config(function($stateProvider) {
	$stateProvider.state('recrut2.dmdreq', {
		url: '/dmdreq',
		templateUrl: './views/DemandRequest.html',
		controller: ['$state', function($state) {
			
		}]
	}).state('recrut2.dmdreq.option', {
		url: '/option',
		templateUrl: './views/slideDR.html',
		controller: ['$rootScope','$scope' ,'$http','$uibModal','$state',function($rootScope,$scope,$http,$uibModal,$state) {
			//console.log($rootScope.demandRequest);
			
			

            $scope.priorities = ["High","Medium"];
            $scope.statuses = ["New","Hold","Open","Cancel","Closed"];
					
			$scope.demandRequest = angular.copy($rootScope.demandRequest);
			
			
			$scope.demandRequest.raiseDate = new Date();
			$scope.demandRequest.targetJoinDate = new Date();
			$scope.format = "MMM/dd/yyyy";
			$scope.altInputFormats = [ 'yyyy/M!/d!' ];
			$scope.popup1 = {
				opened : false
			};
			$scope.popup2 = {	
					opened : false
				};
			$scope.open1 = function() {
				$scope.popup1.opened = true;		
			};
			$scope.open2 = function() {
				$scope.popup2.opened = true;		
			};
			
			
			$scope.confirm = function(){
				//console.log($scope.demandPriority);
				/*$scope.demandPriority.= $scope.demandRequest;*/
				var tobackend = $scope.demandRequest;//got demandrequest
				console.log(tobackend);
				$scope.demand;
				$http({
					method :'POST',
					url: '/DRMS/api/DrmsDemand/findByShowId?showId='+tobackend.demandShowId
				}).then(function(reponse){
					$scope.demand = reponse.data;//got demand
					console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
					console.log($scope.demand);
					console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
					var mail ={
							to :tobackend.recever,
							cc:tobackend.cc,	
							demandShowId:tobackend.demandShowId,
							opnDate:tobackend.openDate,
							capa:$scope.demand.drmsCapability.capName,
							posTit:$scope.demand.dmdPosition,
							desDsg:$scope.demand.drmsDesigation.dsgName,
							hirRes:tobackend.hiringReason,
							billDate:tobackend.billingDate,
							wrkLoc:tobackend.workLocation,
							cusInter:tobackend.custInterview,
							isflp:tobackend.isflp,
							primarySkill:tobackend.primarySkill,
							targetJoinDate:tobackend.targetJoinDate,
							refName:tobackend.refName,
							projIntr:tobackend.projectIntro,
							duty:tobackend.duties,
							other:tobackend.other,
							teches:tobackend.technicalSkills,
							langs:tobackend.languageSkills,
							hcReq:tobackend.hcRequired,
						
						}
						
						console.log(mail);
						$http({
								method : 'POST',
							url:'/DRMS/api/drmsEmail/sendUpdate',
							headers:{
								'Content-type':'application/json'
							},
							data:mail
						}).then(function(){
							
							console.log($scope.demand);
							
						});
				});
				
				
				$http({
					method : 'POST',
					url :'/DRMS/api/demandrequest/updateDrmsDemandRequest',
					headers: {
						'Content-Type': 'application/json'
					},
					data : tobackend
				});

				
				
				
				var modalInstance = $uibModal.open({
                    animation: false,
                    size: 'sm',
                    templateUrl: './views/coralert.html',
                    controller: 'alertController',
                    resolve: {
                         item: function() {
                               return ' DEMADN REQUEST EDIT  SUCCESS.';
                         }
                    }
               });
               
               modalInstance.result.then(function() {
                    //slideCallbackService.promiseDeferd.notify('promise noitfy');
                    //$state.go('^');
            	   	$state.go('recrut2.dmdreq',null,{
               		    reload:true
               		});
            	   
               }, function() {
                   // slideCallbackService.promiseDeferd.notify('promise noitfy');
                    //$state.go('^');
            	
               });
			}	
		}]
	}) 
	.state('recrut2.dmdreq.addPro',{
		url : '/addPro',
		templateUrl: './views/slidePriority.html',
		controller: ['$rootScope','$scope' ,'$http','$uibModal', function($rootScope,$scope,$http, $uibModal) {
			$scope.priorities = ["High","Medium"];
			
			
			$scope.demandRequest = angular.copy($rootScope.demandRequest);
			$scope.demandPriority = {};// must be instanied  
			$scope.demandPriority.weekStart = new Date();
			$scope.demandPriority.weekEnd = new Date();
			$scope.demandPriority.weekEnd = $scope.demandPriority.weekEnd.setDate($scope.demandPriority.weekStart.getDate()+7);
			$scope.format = "yyyy/MM/dd";
			$scope.altInputFormats = [ 'yyyy/M!/d!' ];

			$scope.popup1 = {
				opened : false
			};
			$scope.popup2 = {
					opened : false
				};
			$scope.open1 = function() {
				$scope.popup1.opened = true;		
			};
			$scope.open2 = function() {
				$scope.popup2.opened = true;		
			};

			$scope.confirm = function(){
				
				console.log($scope.demadn);
				
				
				var tobackend = $scope.demandRequest;
				$scope.demandPriority.drmsDemandRequest = tobackend;
				console.log($scope.demandPriority);
				$http({
					method : 'POST',
					url :'/DRMS/api/DrmsDemandRequestPriority/insertDrmsDemandRequestPriority',
					headers: {
						'Content-Type': 'application/json'
					},
					data: $scope.demandPriority
					
					
					
				});
				
				var modalInstance = $uibModal.open({
                    animation: false,
                    size: 'sm',
                    templateUrl: './views/coralert.html',
                    controller: 'alertController',
                    resolve: {
                         item: function() {
                               return ' Priority Add  SUCCESS.';
                         }
                    }
				
					
				
               });
               
               modalInstance.result.then(function() {
                    //slideCallbackService.promiseDeferd.notify('promise noitfy');
            	 /*  $state.go('',null,{
            		    reload:true
            		});
                    */
               }, function() {
                   // slideCallbackService.promiseDeferd.notify('promise noitfy');
                    //$state.go('^');
               });

				
			
			}	
		}]
	})
});